﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using CountdownTool.Annotations;

namespace CountdownTool
{
    public class SettingViewModel : INotifyPropertyChanged
    {

        private int _minuteValue = 20;


        public int MinuteValue
        {
            get => _minuteValue;
            set
            {
                if (_minuteValue != value)
                {
                    if (value < 0)
                    {
                        return;
                    }
                    _minuteValue = value;
                    OnPropertyChanged();
                }
            }
        }

        private int _secondValue = 0;


        public int SecondValue
        {
            get => _secondValue;
            set
            {
                if (_secondValue != value)
                {
                    if (value < 0)
                    {
                        value = 59;
                        MinuteValue--;
                    }
                    if (value > 59)
                    {
                        value = 0;
                        MinuteValue++;
                    }

                    _secondValue = value;
                    OnPropertyChanged();
                }
            }
        }


        private int _intervalValue = 5;


        /// <summary>
        /// 间隔显示的时间（分钟）
        /// </summary>
        public int IntervalValue
        {
            get => _intervalValue;
            set
            {
                if (_intervalValue != value)
                {
                    if (value < 1)
                    {
                        return;
                    }
                    _intervalValue = value;
                    OnPropertyChanged();
                }
            }
        }


        private int _currentMuniteValue;


        public int CurrentMuniteValue
        {
            get => _currentMuniteValue;
            set
            {
                if (_currentMuniteValue != value)
                {
                    _currentMuniteValue = value;
                    OnPropertyChanged();
                }
            }
        }

        private int _currentSecondValue;


        public int CurrentSecondValue
        {
            get => _currentSecondValue;
            set
            {
                if (_currentSecondValue != value)
                {
                    if (value < 0)
                    {
                        value = 59;
                        CurrentMuniteValue--;
                    }
                    if (value > 59)
                    {
                        value = 0;
                        CurrentMuniteValue++;
                    }
                    _currentSecondValue = value;
                    OnPropertyChanged();
                }
            }
        }



        private bool _isOverZero;
        

        public bool IsOverZero
        {
            get => _isOverZero;
            set
            {
                if (_isOverZero != value)
                {
                    _isOverZero = value;
                    OnPropertyChanged();
                }
            }
        }

        private bool _isHoldOn;
        

        public bool IsHoldOn
        {
            get => _isHoldOn;
            set
            {
                if (_isHoldOn != value)
                {
                    _isHoldOn = value;
                    OnPropertyChanged();
                }
            }
        }


        private TimeWindowLocation _timeWindowLocation = TimeWindowLocation.RightUp;
        

        public TimeWindowLocation TimeWindowLocation
        {
            get => _timeWindowLocation;
            set
            {
                if (_timeWindowLocation != value)
                {
                    _timeWindowLocation = value;
                    OnPropertyChanged();
                }
            }
        }





        public void Reset()
        {
            IsOverZero = false;
            CurrentMuniteValue = MinuteValue;
            CurrentSecondValue = SecondValue;
        }










        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

}
